package edu.jxnu.zhangjinsong.unemploymenttracker.config;

import edu.jxnu.zhangjinsong.unemploymenttracker.config.properties.OllamaProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.api.OllamaChatOptions;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 张劲松
 * &#064;date  2025/11/28
 * &#064;description  多模型配置
 */

@Configuration
@Slf4j
@EnableConfigurationProperties(OllamaProperties.class)
public class AiChatConfig {

    private final OllamaProperties ollamaProperties;

    public AiChatConfig(OllamaProperties ollamaProperties) {
        this.ollamaProperties = ollamaProperties;
    }

    @Bean("deepseek-r1")
    public ChatClient DeepseekR1(ChatClient.Builder chatClient) {
        return createChatClient(chatClient,ollamaProperties.getModels().get("deepseek-r1"));
    }

    @Bean("gpt-3.5-turbo")
    public ChatClient Gpt_3_Turbo(ChatClient.Builder chatClient) {
        return createChatClient(chatClient,"gpt-3.5-turbo");
    }


    private ChatClient createChatClient(ChatClient.Builder builder,String modelName) {
        return builder
                .defaultOptions(OllamaChatOptions.builder()
                        .model(modelName)
                        .temperature(ollamaProperties.getTemperature())
                        .build())
                .build();
    }
}
